package com.dcw.lixb.designmode.singleinstance;

/**
 * @author lixiaobin
 * @date 2020-07-16 17:25:21
 * @desc 双检锁/双重校验锁（DCL，即 double-checked locking）
 *是否 Lazy 初始化：是
 *
 * 是否多线程安全：是
 *
 * 实现难度：较复杂
 */
public class SingleD {
    private static SingleD sInstance;

    private SingleD() {
        try {
            Thread.sleep(200L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public  static SingleD getInstance() {
        if (null == sInstance) {
            synchronized (SingleD.class) {
                if (null==sInstance) {
                    sInstance = new SingleD();
                }
            }
        }
        return sInstance;
    }
}
